
public class FruitFactory {
	public static Fruit getFruit(String type) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
		/*
		 * if (type.equalsIgnoreCase("apple")) { return new Apple(); } else if
		 * (type.equalsIgnoreCase("banana")) { return new Banana(); } else { return
		 * null; }
		 */
		
		/*if (type.equalsIgnoreCase("apple")) {
			return Apple.class.newInstance();
		} else if (type.equalsIgnoreCase("banana")) {
			return Banana.class.newInstance();
		} else {
			return null;
		}*/
		
		return (Fruit) Class.forName(type).newInstance();

	}
}
